import 'package:flutter/material.dart';
import 'package:stroke_customer/model/comm/CommArticle.dart';

class CustomerIndexArticle extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return new _CustomerIndexArticleState();
  }

}

class _CustomerIndexArticleState extends State<StatefulWidget> {

  final String eyeUri="images/index/eye.png";

  CommArticle _commArticle;


  ListView _createArticle() {
    List<Widget> dataList = new List<Widget>();
    for (int i = 0; i < _commArticle.data.list.length; i++) {
      Article entity = _commArticle.data.list[i];
      dataList.add(_getArticle(entity));

    }
    ListView articles = new ListView(
      children: dataList,
    );
    return articles;
  }

  Container _getArticle(Article entity) {
    Image image = new Image(
        image: NetworkImage(entity.iconImg),
        width: 80.0,
        height: 60.0,
        fit: BoxFit.fill
    );

    Row arctleTop = new Row(
      children: <Widget>[
        new Container(
          width: 75,
          height: 28,
          decoration: BoxDecoration(
            color: Colors.blue,
            border: Border.all(color:Colors.white,width: 1),
            borderRadius: BorderRadius.circular(20),
          ),
          child: new Text(entity.articleCateDesc),
        ),
        new Text(entity.title)
      ],
    );
    Container arctle1Buttom =
        new Container(
          alignment: Alignment.bottomRight,
          child: new Row(
            children: <Widget>[
              new Image.asset(
                eyeUri,
                width: 16.0,
                height: 11.0,
                fit: BoxFit.cover,
              ),
              new Text(entity.browseAmount.toString()),
            ],
          ),
        );


    return  new Container(
      child: Row(
        children: <Widget>[
          image,
          new Column(
            children: <Widget>[
              arctleTop,
              arctle1Buttom
            ],
          )

        ],
      ),
    );
  }


  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("卒中科普"),
      ),
      body: new Center(
        child:  _createArticle(),
      )

    );
  }


  CommArticle initArticle() {
    Article article =
    new Article(
        1,
        "1",
        1001,
        "",
        1,
        "科普文章",
        1,
        "溶栓报告",
        "什么样的人可以做溶栓治疗",
        "",
        "",
        1,
        "http://image.bladezoff.com/article/20181204162931.png",
        1,
        1,
        "",
        1,
        "",
        "");


    Article article1 =
    new Article(
        1,
        "1",
        1001,
        "",
        1,
        "科普文章",
        1,
        "溶栓报告",
        "卒中急救注意事项",
        "",
        "",
        1,
        "http://image.bladezoff.com/article/20181204162940.png",
        1,
        1,
        "",
        1,
        "",
        "");


    Article article2 =
    new Article(
        1,
        "1",
        1001,
        "",
        1,
        "科普文章",
        1,
        "溶栓报告",
        "如何判断脑卒中",
        "",
        "",
        1,
        "http://image.bladezoff.com/article/20181204162943.png",
        1,
        1,
        "",
        1,
        "",
        "");


    Article article3 =
    new Article(
        1,
        "1",
        1001,
        "",
        1,
        "科普文章",
        1,
        "溶栓报告",
        "什么样的人可以做溶栓治疗",
        "",
        "",
        1,
        "http://image.bladezoff.com/article/20181204162931.png",
        1,
        1,
        "",
        1,
        "",
        "");


    Article article4 =
    new Article(
        1,
        "1",
        1001,
        "",
        1,
        "科普文章",
        1,
        "溶栓报告",
        "什么样的人可以做溶栓治疗",
        "",
        "",
        1,
        "http://image.bladezoff.com/article/20181204162931.png",
        1,
        1,
        "",
        1,
        "",
        "");


    Article article5 =
    new Article(
        1,
        "1",
        1001,
        "",
        1,
        "科普文章",
        1,
        "溶栓报告",
        "什么样的人可以做溶栓治疗",
        "",
        "",
        1,
        "http://image.bladezoff.com/article/20181204162931.png",
        1,
        1,
        "",
        1,
        "",
        "");


    Article article6 =
    new Article(
        1,
        "1",
        1001,
        "",
        1,
        "科普文章",
        1,
        "溶栓报告",
        "什么样的人可以做溶栓治疗",
        "",
        "",
        1,
        "http://image.bladezoff.com/article/20181204162931.png",
        1,
        1,
        "",
        1,
        "",
        "");


    Article article7 =
    new Article(
        1,
        "1",
        1001,
        "",
        1,
        "科普文章",
        1,
        "溶栓报告",
        "什么样的人可以做溶栓治疗",
        "",
        "",
        1,
        "http://image.bladezoff.com/article/20181204162931.png",
        1,
        1,
        "",
        1,
        "",
        "");


    List<Article> articles = new List<Article>();
    articles.add(article);
    articles.add(article1);
    articles.add(article2);

    Data pageData = new Data(
        1,
        1,
        1,
        1,
        1,
        10,
        1,
        articles,
        1,
        1,
        true,
        false,
        false,
        false,
        1,
        1,
        1,
        1,
        1);

    return CommArticle(pageData, '0', "Success");
  }

  @override
  // ignore: must_call_super
  void initState() {
    _commArticle = initArticle();
    print(_commArticle.toString() + "*******************");
  }

}